<?php
	$facebook = variable('facebook', false);
	$poff = variable('blogi', false);
?>
<?php if($facebook != 'facebook'): ?>
<div class="facebook_icon"><a href="<?php echo $facebook ?>" target="_blank"><img src="/anima/images/facebook_icon.png" width="45" height="52" alt="" /></a></div>
<?php endif; ?>
<?php if($poff != 'blogi'): ?>
<div class="blog_icon"><a href="<?php echo $poff ?>" target="_blank"><img src="/anima/images/blog_icon.png" width="45" height="52" alt="" /></a></div>
<?php endif; ?>

<div class="newsletter_slide" style="display:none">
<a class="handle" href="http://google.com">Content</a> <span class="txtstyle1"><?php __('PÖFFi Postiljon')?></span> <?php echo __('Telli PÖFFi uudiskiri') ?>
	<form action="<?php include_component('linker', 'plainActions', array('module' => 'homepage', 'action'=> 'joinMailGroup')) ?>" method="post" id="mailer">
		<input class="mail_field" name="email" type="text" value="E-Mail" onfocus="clear_field(this,'E-Mail')" onblur="clear_reset(this,'E-Mail')" />
		<span class="mailtitle"><?php echo __('Vali liitumiseks listid') ?>:</span><br />
		<br />
		<input class="styled" id="all_selection" value="0" type="checkbox" name="grupp[]" />
		<span class="checkbox_txt"><?php echo __('KÕIK') ?></span>
		<input class="styled" value="4" type="checkbox" name="grupp[]" />
		<span class="checkbox_txt">Animated Dreams</span>
		<input class="styled" value="2" type="checkbox" name="grupp[]" />
		<span class="checkbox_txt"><?php echo __('PÖFF') ?></span>
		<input class="styled" value="8" type="checkbox" name="grupp[]" />
		<span class="checkbox_txt"><?php echo __('Kumu dokumentaal') ?></span>
		<input class="styled" value="6" type="checkbox" name="grupp[]" />
		<span class="checkbox_txt"><?php echo __('HÕFF') ?></span>
		<input class="styled" value="7" type="checkbox" name="grupp[]" />
		<span class="checkbox_txt"><?php echo __('tARTuFF') ?></span>
		<input class="styled" value="3" type="checkbox" name="grupp[]" />
		<span class="checkbox_txt"><?php echo __('Sleepwalkers') ?></span>
		<input class="styled" value="5" type="checkbox" name="grupp[]" />
		<span class="checkbox_txt"><?php echo __('Just Film') ?></span>
		<input id="mailer_submit" class="mail_button" type="submit" value="<?php echo __('Liitu') ?>" />
	</form>
	<div style="clear:both"></div>
	<div id="liitu_error" style="display: block;padding-top:3px;text-align:center; font-size:12px; color:red;"></div>
</div>

<script type="text/javascript">
$(document).ready(function(){
	
	$('.handle').click(function(){
		$('.checkbox').siblings('#all_selection').prev().click(function(e){
			var input = $('#all_selection');
			if(input.is(':checked')){
				$('span[class=checkbox]').each(function(e){
					if(!$(this).next().is(':checked')){
						$(this).trigger('mousedown');
						$(this).trigger('mouseup');
					}
				});
			}else{
				$('span[class=checkbox]').each(function(e){
					if($(this).next().is(':checked')){
						$(this).trigger('mousedown');
						$(this).trigger('mouseup');
					}
				});
			}
		});
	});
});

jQuery('#mailer_submit').click(function(e){
	e.preventDefault();

	var form = $(this).parent('form');
	var data  = form.serialize();

	$.post(form.attr('action'), data, function(response){

		if(response.code == 500){
			$('#liitu_error').html(response.message);
		}else{
			$('#liitu_error').html('');
			$.prompt(response.message,{
				buttons: { OK:false }
			});
		}

	},'json');

	return false;
});
</script>